//
//  RSAutolayoutTextViewCellVC.m
//  RSTools
//
//  Created by thinkjoy on 2017/9/15.
//  Copyright © 2017年 杜瑞胜. All rights reserved.
//

#import "RSAutolayoutTextViewCellVC.h"
#import "RSAutolayoutTextViewCell.h"

#define kWinH ([[UIScreen mainScreen] bounds].size.height)
#define kWinW ([[UIScreen mainScreen] bounds].size.width)

@interface RSAutolayoutTextViewCellVC ()<UITableViewDelegate,UITableViewDataSource>

@property   (nonatomic,strong)  UITableView * mainTableView;
@property   (nonatomic, strong) NSMutableArray *dataMuAry;

@end

@implementation RSAutolayoutTextViewCellVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _mainTableView  =   [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWinW, kWinH) style:UITableViewStylePlain];
    _mainTableView.delegate =   (id)self;
    _mainTableView.dataSource   =   (id)self;
    [self.view addSubview:_mainTableView];
    
    _mainTableView.estimatedRowHeight = 100;
    _mainTableView.rowHeight = UITableViewAutomaticDimension;
    
    _dataMuAry  =   [NSMutableArray arrayWithCapacity:30];
    
    for (int i=0; i<30; i++) {
        [_dataMuAry addObject:@""];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataMuAry.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RSAutolayoutTextViewCell *cell = [RSAutolayoutTextViewCell getRSAutolayoutTextViewCellWithTableView:tableView];

    cell.infoDic    =   @{TableViewTextKey:self.dataMuAry[indexPath.row],
                          TableViewPlaceholderKey:[NSString stringWithFormat:@"请输入第%d行",(int)indexPath.row]};

    [cell setDidChangeTextBlock:^(NSString * text){
        [self.dataMuAry replaceObjectAtIndex:indexPath.row withObject:text];
    }];
    
    return cell;
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
